package com.eazyimage.lab.service;

import com.eazyimage.lab.entity.Dataeachnum;
import com.eazyimage.lab.mapper.VerifygenMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eazyimage.lab.entity.Dataset_;

import java.util.HashMap;
import java.util.List;

@Service
public class Verifygenservice {
    @Autowired
    VerifygenMapper vm;
    @Autowired
    PackageMesService pm;


    public String Generateverify(int Datasetid){

        String ori = vm.Toverify( Datasetid);
        Md5Service md = new Md5Service();
        String verify = md.start(ori);
        //System.out.print("\n");System.out.print(verify);System.out.print("\n");
        while(vm.Verifyonly(verify)!=0)
        {
            ori = ori+"1";
            verify = "";
            md = new Md5Service();
            verify = md.start(ori);
        }
        vm.GenerateVerify(verify,Datasetid);
        return verify;
    }
    public Dataset_ Findbyverify(String verify){
        return vm.Findbyverify(verify);
    }

    public List<Dataset_> Findbyispublic(){
        return vm.Findbyispublic();
    }

    public HashMap<Integer,List<Dataeachnum>> getpublicdatasetid()
    {
        HashMap<Integer,List<Dataeachnum>> result = new HashMap<>();
        List<Integer> usid =  vm.getpublicdatasetid();
        for(int id : usid){
            result.put(id, pm.Selectnum(Integer.toString(id)));
        }
        return result;
    }
}
